package com.lsk.netdisk.gateway.util;

import com.lsk.netdisk.common.response.core.ResponseParser;
import com.lsk.netdisk.gateway.models.Response;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.Map;

@Slf4j
public final class WebUtil {
	public static String getCookieValue(Cookie[] cookies, String name){
		for (Cookie cookie : cookies){
			if (cookie.getName().equals(name)){
				return cookie.getValue();
			}
		}
		return null;
	}
	public static Object processResponse(Response response, HttpServletResponse resp){
		response.addToResp(resp);
		LinkedHashMap respMap = (LinkedHashMap) response.getRespData();
		//String stringData = ((LinkedHashMap)data).toString();
		//log.info(stringData);
		Integer code = (Integer)respMap.get("code");
		String message = (String)respMap.get("message");
		Object data = respMap.get("data");
		return new com.lsk.netdisk.common.response.core.Response(code,message,data);
	}
}
